package gamePackage;

//Imports
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Player {

	int x, xMove, y, yMove; //Player attributes
	Image play; //Player image variable
	
	//Constructor
	public Player() {
		
		//Retrieve playable character image
		ImageIcon imgGet = new ImageIcon("game/player.png");
		play = imgGet.getImage();
		
		//Player spawn
		x = 50;
		y = 200;
		
	} //End constructor

	public void move() { //Move method
		
		//Add values to relocate character
		if (x + xMove <= 0) //Left border
			x++;
		else if (x + xMove >= 800) //Right border
			x--;
		else {
			x = x + xMove;
		}
		if (y + yMove <= 0) //Top border
			y++;
		else if (y + yMove >= 400) //Bottom border
			y--;
		else {
			y = y + yMove;
		}
		
	} //End move method
	
	public int playerX() { //Return x method
		
		return x;
		
	} //End return x method
	
	public int playerY() { //Return y method
		
		return y;
		
	} //End return y method
	
	public Image getPlay() { //Return player image
		
		return play;
		
	}
	
	public void keyPressed(KeyEvent e) { //Key down method
		
		int key = e.getKeyCode(); //returns value of key pressed
		
		//Assign value to move characters to corresponding key press
		if (key == KeyEvent.VK_RIGHT) {
			xMove = 2;
		}
		if (key == KeyEvent.VK_LEFT) {
			xMove = -1;
		}
		if (key == KeyEvent.VK_UP) {
			yMove = -1;
		}
		if (key == KeyEvent.VK_DOWN) {
			yMove = 1;
		}
	
	} //End key down method
		
	public void keyReleased(KeyEvent e) { //Key up method
			
		int key = e.getKeyCode(); //returns value of key released
			
		//Set move value to 0 if key is lifted
		if (key == KeyEvent.VK_RIGHT) {
			xMove = 0;
		}
		if (key == KeyEvent.VK_LEFT) {
			xMove = 0;
		}
		if (key == KeyEvent.VK_UP) {
			yMove = 0;
		}
		if (key == KeyEvent.VK_DOWN) {
			yMove = 0;
		}
		
	} //End key up method
	
}
